//
//  WmcRecognitionMarkView.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/10/31.
//

import UIKit

class WmcRecognitionMarkView: WmcBaseView {
    // Lifecycle

    convenience init(style: Style, radius: Double, index: Int, fontSize: Double) {
        self.init()
        self.style = style
        self.layer.cornerRadius = radius
        self.layer.masksToBounds = true

        if style == .recognition {
            self.backgroundColor = .wmc_green_8AD240
        } else if style == .custom {
            self.backgroundColor = .wmc_red_F54A45
        }
        
        self.numLabel.text = "\(index)"
        self.numLabel.font = UIFont.systemFont(ofSize: fontSize)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required convenience init?(coder: NSCoder) {
        self.init(frame: .zero)
    }
    
    private lazy var numLabel: UILabel = {
        let label = UILabel()
        label.minimumScaleFactor = 0.5
        label.adjustsFontSizeToFitWidth = true
        label.textColor = .wmc_white_FFFFFF
        label.font = UIFont.systemFont(ofSize: 8)
        label.textAlignment = .center
        return label
    }()

    // Internal

    enum Style {
        case recognition
        case custom
    }

    private(set) var style: Style = .recognition

    override func makeUI() {
        addSubview(numLabel)
        
        numLabel.snp.makeConstraints { make in
            make.left.equalTo(1)
            make.right.equalTo(-1)
            make.centerY.equalToSuperview()
        }
    }
    
    func setIndexLabel(_ index: Int) {
        self.numLabel.text = "\(index)"
    }
}
